﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace dpdw.Behaviour.OberverPattern
{
    public class WeatherData : Subject
    {
        private ArrayList observers;

        private float temperature;
        private float humidity;
        private float pressure;

        public WeatherData()
        {
            this.observers = new ArrayList();
        }

        public void RegisterObserver(Observer o)
        {
            observers.Add(o);
        }

        public void RemoveObserver(Observer o)
        {
            observers.Remove(o);
        }

        public void NotifyObservers()
        {
            for (int i = 0; i < observers.Count; i++)
            {
                Observer o = observers[i] as Observer;
                o.Update(temperature, humidity, pressure);
            }
        }

        public void MeasurementsChanged()
        {
            this.NotifyObservers();
        }

        public void RefreshMeasurements(float temperature, float humidity, float pressure)
        {
            this.temperature = temperature;
            this.humidity = humidity;
            this.pressure = pressure;

            this.MeasurementsChanged();
        }
    }
}
